package com.ejd.web.vo.manage.goods;

import java.io.Serializable;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import net.sf.cglib.beans.BeanCopier;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.utils.ValidatorUtil;
import com.ejd.web.bo.impl.Customer;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.ManageBeanConstants;
import com.ejd.web.constant.SpringBeanConstants;
import com.ejd.web.vo.common.ConsigneeVo;
import com.ejd.web.vo.common.CustomerVo;
import com.ejd.web.vo.common.GoodsPropertiesVo;

public class GoodsPropertiesCrudBean implements Serializable {

	private String actionOfProperties;
	private GoodsPropertiesVo goodsPropertiesVo = new GoodsPropertiesVo();
	private Integer selectedRow;//for edit
	public List<String> errorMessages = new ArrayList<String>();
	//end
	public GoodsPropertiesCrudBean(){
	}
	

	public List<String> getErrorMessages() {
		return errorMessages;
	}


	public void setErrorMessages(List<String> errorMessages) {
		this.errorMessages = errorMessages;
	}


	public String getActionOfProperties() {
		return actionOfProperties;
	}

	public void setActionOfProperties(String actionOfProperties) {
		this.actionOfProperties = actionOfProperties;
	}

	public GoodsPropertiesVo getGoodsPropertiesVo() {
		return goodsPropertiesVo;
	}


	public void setGoodsPropertiesVo(GoodsPropertiesVo goodsPropertiesVo) {
		this.goodsPropertiesVo = goodsPropertiesVo;
	}



	public Integer getSelectedRow() {
		return selectedRow;
	}


	public void setSelectedRow(Integer selectedRow) {
		this.selectedRow = selectedRow;
	}

	protected static List<String> validateInputDataNotEmpty(GoodsPropertiesVo editGoodsPropertiesVo,List<String> errorMessages){
		List<String> result = errorMessages;
		FacesMessage message;
		if (ValidatorUtil.isEmpty((null == editGoodsPropertiesVo.getColor())?null:editGoodsPropertiesVo.getColor())) {
			
			message = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME, "color.must.input.error.message", FacesMessage.SEVERITY_ERROR);
	 		errorMessages.add(message.getDetail());
		}
		if (ValidatorUtil.isEmpty((null == editGoodsPropertiesVo.getSize())?null:editGoodsPropertiesVo.getSize())) {
			
			message = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME, "size.must.input.error.message", FacesMessage.SEVERITY_ERROR);
	 		errorMessages.add(message.getDetail());
		}
		if (null == editGoodsPropertiesVo.getNumber()) {
			editGoodsPropertiesVo.setNumber(new Integer(1));
		}
		
		return result;
	}
	public void clearErrorMessages() {
		if (null != this.getErrorMessages() && this.getErrorMessages().size() > 0) {
			this.getErrorMessages().clear();
		}
	}
	public String closeGoodsPorpertiesPanel() {
		this.setActionOfProperties("");
		return null;
	}
	public void changeColor(ValueChangeEvent event) {
		String newValue = (String)event.getNewValue();
		this.getGoodsPropertiesVo().setColor(newValue);
		clearErrorMessages();
	}
	public void changeSize(ValueChangeEvent event) {
		String newValue = (String)event.getNewValue();
		this.getGoodsPropertiesVo().setSize(newValue);
		clearErrorMessages();
	}
	public void changeNumber(ValueChangeEvent event) {
		Integer newValue = (Integer)event.getNewValue();
		this.getGoodsPropertiesVo().setNumber(newValue);
		clearErrorMessages();
	}
}
